package actions;

import java.sql.SQLException;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.StudentForm;
import model.UniversityModel;

public class StudentResidencyAction extends Action {

	private static final boolean DEBUG = true;
	//private static final int UNKNOWN = -1;
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws DbException {
	
		// get student name from form
		StudentForm sform = (StudentForm)form;
		
		String residency = (request.getSession().getAttribute("residence").equals("United States"))? 
							"true" : sform.getResidency();
		
		// saving residency to session
		request.getSession().setAttribute("residency", residency);
		
		
		if (DEBUG) {
			System.err.println("StudentResidencyAction: saving residency(" + residency +")");
		}
		
		// store StudentForm into session
		sform = (StudentForm)request.getSession().getAttribute("sform");
		
		sform.setResidency(residency);
		
		int degrees_count = 0;
		
		request.getSession().setAttribute("degrees_count", degrees_count);
		
		if (DEBUG) {
			System.err.println("StudentResidencyAction: form first_name(" + sform.getFname() +")");
			System.err.println("StudentResidencyAction: form middle_name(" + sform.getMname() +")");
			System.err.println("StudentResidencyAction: form last_name(" + sform.getLname() +")");
			System.err.println("StudentResidencyAction: form citizenship(" + sform.getCitizen() +")");
			System.err.println("StudentResidencyAction: form residence(" + sform.getResidence() +")");
			System.err.println("StudentResidencyAction: form address(" + sform.getAddress() +")");
			System.err.println("StudentResidencyAction: form city(" + sform.getCity() +")");
			System.err.println("StudentResidencyAction: form state(" + sform.getState() +")");
			System.err.println("StudentResidencyAction: form zip code(" + sform.getZip_code() +")");
			System.err.println("StudentResidencyAction: form country code(" + sform.getCountry_code() +")");
			System.err.println("StudentResidencyAction: form area code(" + sform.getArea_code() +")");
			System.err.println("StudentResidencyAction: form telephone(" + sform.getTelephone() +")");
			System.err.println("StudentResidencyAction: form residency(" + sform.getResidency() +")");
		}
		
		return mapping.findForward("success");
	}
	
}
